home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 May / PCpro_2005_05.ISO / files / mut / 9430830 / client.swf / scripts / %3Cdefault package%3E / QLODKerningComponentSymbol.as next >
Encoding:
Text File  |  2004-12-15  |  2.7 KB  |  115 lines

  1. function QLODKerningClass(kerning, autoSize, autoKern, targetName)
  2. {
  3.    if(autoSize != undefined)
  4.    {
  5.       this.autoSizeToKern = autoSize;
  6.    }
  7.    if(autoKern != undefined)
  8.    {
  9.       this.autoKernToSize = autoKern;
  10.    }
  11.    if(targetName != undefined)
  12.    {
  13.       this._targetInstanceName = targetName;
  14.    }
  15.    if(kerning != undefined)
  16.    {
  17.       this.setKerning(kerning);
  18.    }
  19.    else
  20.    {
  21.       this.setKerning(this.kerning);
  22.    }
  23. }
  24. o = QLODKerningClass.prototype = new MovieClip();
  25. Object.registerClass("QLODKerningComponentSymbol",QLODKerningClass);
  26. o.setKerning = function(kerning)
  27. {
  28.    this.kerning = kerning;
  29.    var _loc5_ = this._parent[this._targetInstanceName];
  30.    if(_loc5_ == undefined)
  31.    {
  32.       trace("QLODKerningClass::update target not defined: " + this._targetInstanceName + "--------------- WARNING");
  33.       return undefined;
  34.    }
  35.    if(!(_loc5_ instanceof TextField))
  36.    {
  37.       trace("QLODKerningClass::update target is not a TextField: " + _loc5_ + "--------------- WARNING");
  38.       return undefined;
  39.    }
  40.    var _loc7_ = [];
  41.    var _loc4_ = _loc5_.text;
  42.    var _loc6_ = null;
  43.    var _loc2_ = 0;
  44.    var _loc3_ = "";
  45.    var _loc8_ = null;
  46.    var _loc11_ = 0;
  47.    var _loc9_ = "";
  48.    _loc2_ = 0;
  49.    while(_loc2_ < _loc4_.length)
  50.    {
  51.       _loc3_ = _loc4_.charAt(_loc2_);
  52.       if(_loc3_ >= " ")
  53.       {
  54.          _loc9_ += _loc3_;
  55.       }
  56.       _loc2_ = _loc2_ + 1;
  57.    }
  58.    _loc4_ = _loc9_;
  59.    _loc9_ = "";
  60.    kerning = this.kerning;
  61.    trace("kerning:" + kerning);
  62.    if(isNan(kerning))
  63.    {
  64.       kerning = 2;
  65.    }
  66.    else if(kerning < 2)
  67.    {
  68.       kerning = 0;
  69.    }
  70.    _loc2_ = 0;
  71.    while(_loc2_ < _loc4_.length)
  72.    {
  73.       _loc3_ = _loc4_.charAt(_loc2_);
  74.       _loc6_ = _loc5_.getTextFormat(_loc2_);
  75.       _loc8_ = _loc6_.getTextExtent(_loc3_);
  76.       _loc11_ += _loc8_.width;
  77.       _loc7_.push(_loc8_.width);
  78.       _loc9_ += _loc3_ + "\t";
  79.       _loc2_ = _loc2_ + 1;
  80.    }
  81.    if(this.autoKernToSize)
  82.    {
  83.       delete _loc5_.autoSize;
  84.       kerning = Math.max(Math.floor((_loc5_._width - _loc11_) / _loc4_.length),kerning);
  85.    }
  86.    else if(this.autoSizeToKern)
  87.    {
  88.       _loc5_.autoSize = "left";
  89.    }
  90.    if(kerning == 0)
  91.    {
  92.       _loc6_ = _loc5_.getTextFormat();
  93.       _loc5_.text = _loc4_;
  94.       _loc6_.tabStops = [];
  95.       _loc5_.setTextFormat(_loc6_);
  96.    }
  97.    else
  98.    {
  99.       _loc11_ = 0;
  100.       var _loc12_ = [];
  101.       _loc2_ = 0;
  102.       while(_loc2_ < _loc7_.length)
  103.       {
  104.          _loc12_[_loc2_] = _loc11_;
  105.          _loc11_ += _loc7_[_loc2_] + kerning;
  106.          _loc2_ = _loc2_ + 1;
  107.       }
  108.       _loc5_.text = _loc9_;
  109.       _loc6_ = _loc5_.getTextFormat();
  110.       _loc6_.tabStops = _loc12_;
  111.       _loc5_.setTextFormat(_loc6_);
  112.    }
  113. };
  114. delete o;
  115.